package org.lc.cmd.plugin.scan;

import org.jline.console.impl.JlineCommandRegistry;
import org.lc.cmd.Command;
import org.lc.cmd.CommandRegistry;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Component
public class DefaultCommandRegistry extends JlineCommandRegistry implements CommandRegistry {
    private Map<String, Command> commands;

    @Override
    public List<String> commandInfo(String command) {
        return Collections.emptyList();
    }

    /**
     * 注册命令
     *
     * @param commands 命令
     */
    @Override
    public void registerCommands(List<Command> commands) {
        this.commands = commands.stream().collect(Collectors.toMap(Command::getName, Function.identity()));
        registerCommands(commands.stream().collect(Collectors.toMap(Command::getName, Command::toCommandMethods)));
    }

    @Override
    public Map<String, Command> getCommands() {
        return commands;
    }
}
